<?php
require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

//建立一个连接通道，声明一个可以发送消息的队列hello  
$connection = new AMQPStreamConnection('39.108.170.27', 5672, 'guest', 'guest');
$channel = $connection->channel();
//声明一个队列
$channel->queue_declare('hello', false, false, false, false);

//定义一个消息，消息内容为Hello World!  
$msg = new AMQPMessage('Hello World!');

//向队列发布消息
$channel->basic_publish($msg, '', 'hello');

//发送完成后打印消息告诉发布消息的人：发送成功  
echo " [x] Sent 'Hello World!'\n";

//关闭通道和连接
$channel->close();
$connection->close();